home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Swar / game.c < prev    next >
Text File  |  1994-08-21  |  1KB  |  77 lines

  1.  
  2. #include "swar.h"
  3.  
  4. InitGame()
  5. {    
  6.     NewMatch();
  7.     
  8. } /* InitGame() */
  9.  
  10. GameCycle()
  11. {
  12.     GrafPtr        savePort;
  13.     Rect        bigRect;
  14.     extern CWindowPtr        gPictureWindow;
  15.     extern CGrafPort        *gOSPtr;
  16.     extern Boolean            gMatchIsEnding, gPlaying;
  17.     extern short            gMatchTicker;
  18.     extern RGBColor        myWhite, myBlack;
  19.     
  20.     bigRect.top = 0;
  21.     bigRect.bottom = 479;
  22.     bigRect.left = 0;
  23.     bigRect.right = 639;
  24.     GetPort(&savePort);
  25.     SetPort((GrafPtr)gPictureWindow);
  26.     CheckKeyboard();
  27.     MoveObjects();
  28.     if (!gPlaying)
  29.         return;
  30.     DrawObjects();
  31.     SetPort(savePort);
  32.     
  33.     if (gMatchIsEnding && (--gMatchTicker == 0)) {
  34.         RGBForeColor(&myBlack);
  35.         RGBBackColor(&myBlack);
  36.         EraseRect(&bigRect);
  37.         RGBForeColor(&myBlack);
  38.         RGBBackColor(&myWhite);
  39.         NewMatch();
  40.     } /* if */
  41.     
  42. } /* GameCycle() */
  43.  
  44. MoveObjects()
  45. {
  46.     MoveShips();
  47.     MoveShots();
  48.     MoveDebris();
  49.  
  50. } /* MoveObjects() */
  51.  
  52. DrawObjects()
  53. {
  54.     
  55.     DrawStars();
  56.     DrawShips();
  57.     DrawShots();
  58.     DrawDebris();
  59.  
  60. } /* DrawObjects() */
  61.  
  62. NewMatch()
  63. {
  64.     extern Handle        gNewMatchSoundH;
  65.     extern Boolean        gMatchIsEnding;
  66.     
  67.     AStopSnd();
  68.     AInitSnd();
  69.     InitStars();
  70.     InitShips();
  71.     InitShots();
  72.     InitDebris();
  73.     ASndPlay(gNewMatchSoundH);
  74.     gMatchIsEnding = FALSE;
  75.     
  76. } /* NewMatch() */
  77.